import image
import time

class ObjectBase(image.Image):
    def __init__(self, pathFmt, pathIndex, pos, size=None, pathIndexCount=0):
        super().__init__(pathFmt, pathIndex, pos, size, pathIndexCount)
        self.preIndexTime = 0

    def update(self):
        self.checkImageIndex()
        self.checkPosition()


    def checkImageIndex(self):
        if time.time() -self.preIndexTime <= 0.2:
           return
        self.preIndexTime = time.time()
        idx = self.pathIndex+1
        if idx >= self.pathIndexCount:
            idx = 0
        self.updateIndex(idx)

    # 检测移动位置
    def checkPosition(self):
        if time.time() - self.prePostionTime <= 0.2:
            return
        self.prePostionTime = time.time()
        self.pos[0] -= 2.5